VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Detail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
'/******************************************************************/
'/*                                                                */
'/*                      TurboCAD for Windows                      */
'/*                   Copyright (c) 1993 - 2001                    */
'/*             International Microcomputer Software, Inc.         */
'/*                            (IMSI)                              */
'/*                      All rights reserved.                      */
'/*                                                                */
'/******************************************************************/

'DBAPI constants
Const gkGraphic = 11
Const gkArc = 2
Const gkText = 6
Const gfCosmetic = 128&

'Useful math constants
Const Pi# = 3.14159265

'Real variant types!
Const typeEmpty = 0
Const typeInteger = 2
Const typeLong = 3
Const typeSingle = 4
Const typeDouble = 5
Const typeCurrency = 6
Const typeDate = 7
Const typeString = 8
Const typeObject = 9
Const typeBoolean = 11
Const typeVariant = 12
Const typeIntegerEnum = typeInteger + 100
Const typeLongEnum = typeLong + 100
Const typeStringEnum = typeString + 100

'Stock property pages
Const ppStockPen = 1
Const ppStockBrush = 2
Const ppStockText = 4
Const ppStockInsert = 8
Const ppStockViewport = 16
Const ppStockAuto = 32

'Property Ids
Const idBoltType = 1
Const idNutType = 2
Const idDiam = 3

'Property enums
Const NUM_TYPEBOLT = 2
Const Bolt1 = 0
Const Bolt2 = 1
Const NUM_TYPENUT = 2
Const Nut1 = 0
Const Nut2 = 1


'Number of properties, pages, wizards
Const NUM_PROPERTIES = 3
Const NUM_PAGES = 1
Const NUM_WIZARDS = 0
Const formCaption = "Bolt-Nut"

Private Sub Class_Initialize()
    'Initialize class variables
End Sub

'Returns the user-visible description of this RegenMethod
Public Property Get Description() As String
    Description = "BoltNut"
End Property

'Returns the persistent class id for this RegenMethod's property section
Public Property Get ClassID() As String
    ClassID = "{FDB6F1C1-9631-11d1-A40A-0000B465872B}"
End Property

'Retrieve types and names
Public Function GetPropertyInfo(Names As Variant, Types As Variant, _
    IDs As Variant, Defaults As Variant) As Long
    ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), _
        IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
    Names(0) = "BoltType"
    Types(0) = typeLong
    IDs(0) = idBoltType
    Defaults(0) = Bolt1
    
    Names(1) = "NutType"
    Types(1) = typeLong
    IDs(1) = idNutType
    Defaults(1) = Nut1
    
    Names(2) = "Diameter"
    Types(2) = typeDouble
    IDs(2) = idDiam
    Defaults(2) = 0.5
    
    GetPropertyInfo = NUM_PROPERTIES
End Function

'Get the number of property pages supporting this RegenMethod
Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, _
    Names As Variant) As Long
    ReDim Names(NUM_PAGES)

    'Need the form
'    Load frmBoltNut
'    Names(0) = frmBoltNut.Caption
'    Unload frmBoltNut
    Names(0) = formCaption
    StockPages = ppStockBrush + ppStockPen + ppStockAuto
    GetPageInfo = NUM_PAGES
End Function

Public Function GetWizardInfo(Names As Variant) As Long
    ReDim Names(NUM_WIZARDS)
    GetWizardInfo = NUM_WIZARDS
End Function

'Enumerate the names and values of a specified property
Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long

    If PropID = idBoltType Or PropID = idNutType Then
ReDim Names(NUM_TYPEBOLT), Value(NUM_TYPEBOLT)
        Names(0) = "Bolt1"
        Values(0) = Bolt1
    
        Names(1) = "Bolt2"
        Values(1) = Bolt2
        GetEnumNames = NUM_TYPEBOLT
        Exit Function
    End If
    If PropID = idNutType Then
ReDim Names(NUM_TYPENUT), Value(NUM_TYPENUT)
        Names(0) = "Nut1"
        Values(0) = Nut1
    
        Names(1) = "Nut2"
        Values(1) = Nut2
        GetEnumNames = NUM_TYPENUT
        Exit Function
    End If
        
        GetEnumNames = 0
    
End Function

Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
        'Set up error function
        On Error GoTo Failed
Dim i%, j%
Dim Diameter#
Dim iDiam%
        If SaveProperties Then
            'OK button on property page was clicked
            'Form is still loaded
            With frmBoltNut
                'Need On Error statement for the case where you have
                'RRect Turbo Shape and ahother "shape" selected
                On Error Resume Next
                For i = 0 To NUM_TYPEBOLT
                    If .BoltType(i).Value Then
                        Graphic.Properties("BoltType") = i
                        Exit For
                    End If
                Next i
                For j = 0 To NUM_TYPENUT
                    If .NutType(j).Value Then
                        Graphic.Properties("NutType") = j
                        Exit For
                    End If
                Next j
'                iDiam = .ListDiam.ListIndex
'                Graphic.Properties("Diameter") = iDiam
                Diameter = 0#
                On Error Resume Next
                Diameter = CDbl(.ListDiam.Text)
                If Diameter < 0.00001 Then Diameter = 0.5
                                
                Graphic.Properties("Diameter") = Diameter
                
                'When the property page is closed, transfer the numeric
                'Diameter value from the TextBox to the Graphic
                'Get the value as a double-precision number
                
                'Make sure it's between 0 and 100
                
                'Set the roundness property value in the Graphic
            End With
        Else
            'Property page is about to be opened
            'Make sure the form is loaded
            Load frmBoltNut
            With frmBoltNut
            
Dim BoltProp As Variant
                BoltProp = Graphic.Properties("BoltType")
                If VarType(BoltProp) <> vbEmpty Then
                    i = CInt(BoltProp)
                    .BoltType(i).Value = True
                End If
Dim NutProp As Variant
                NutProp = Graphic.Properties("NutType")
                If VarType(NutProp) <> vbEmpty Then
                    j = CInt(NutProp)
                    .NutType(j).Value = True
                End If
'                iDiam = Graphic.Properties("Diameter")
'                .ListDiam.ListIndex = iDiam
                Diameter = Graphic.Properties("Diameter")
Dim Diami#
                iDiam = -1
                For i = 0 To .ListDiam.ListCount - 1
                    Diami = CDbl(.ListDiam.List(i))
                    If Abs(Diameter - Diami) < 0.00001 Then
                        iDiam = i
                    End If
                Next i
                If iDiam = -1 Then iDiam = 4
                
                .ListDiam.ListIndex = iDiam
                                
                'If more than one RRect is selected and they do not
                'have the same properties, don't set up this field
                On Error GoTo NoRType

                'When the property page is opening, transfer the numeric
                'roundness value from the Graphic to the TextBox
                'Get the roundness property value from the Graphic
                'Set the TextBox control's text
NoRType:
            End With
        End If

        PageControls = True
        Exit Function

Failed:
        'For debugging purposes, report that an error occurred
        If Err.Number <> 0 Then
            MsgBox "Error in PageControls: " & Err.Description
        End If

        'Return false if an error occurred
        PageControls = False
End Function

Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
        'Done with form
        Unload frmBoltNut
End Function

Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
    With frmBoltNut
        .Show vbModal
        PropertyPages = Not .DialogCanceled
    End With
End Function

Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
    Wizard = False
End Function

'Called when vertex has been moved, or other geometry change
Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
    'Do nothing
End Function

'Called when vertex is moved, or other geometry change
Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
    'OK to continue with change
    OnGeometryChanging = True
End Function

Public Function OnNewGraphic(ByVal grfThis As Object, ByVal boolCopy As Boolean) As Boolean
    If boolCopy Then
        'Vertices are already added for us...
        OnNewGraphic = True
        Exit Function
    End If

    On Error GoTo Failed
    'New Graphic being created
    'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
    'First Vertex is "first point of axis"
    grfThis.Vertices.Add 0#, 0#, 0#, False, True, False, True, False
    
    'Second Vertex is "Second point of axis"
    
    grfThis.Vertices.Add 3#, 0#, 0#, False, True, False, True, False
    
    grfThis.Properties("LimitVertices") = 2
    OnNewGraphic = True
    Exit Function

Failed:
    'Return false on failure
    OnNewGraphic = False
End Function

'Function called whenever a copy of a graphic is being made
Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
    'Return false on failure
    OnCopyGraphic = True
End Function

'Notification function called after graphic property is saved
Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
        ValueOld As Variant, ValueNew As Variant)
    'Do nothing
End Function

'Notification function called when graphic property is saved
Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
        ValueOld As Variant, ValueNew As Variant) As Boolean
    'OK to proceed
    OnPropertyChanging = True
End Function

'Notification function called when graphic property is retrieved
Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
    'Do nothing
End Function

'Called when we need to update our object
Public Function Regen(ByVal grfThis As Object)
        'Setup error handler
        On Error GoTo Failed

        'Set up lock (prevent recursion)
        Dim LockCount&
        LockCount& = grfThis.RegenLock

        'Setup error handler (make sure lock is removed)
        On Error GoTo FailedLock
        If LockCount& = 0 Then
            'Delete any previous cosmetic children
            grfThis.Graphics.Clear gfCosmetic
            
Dim BoltType As Long
            BoltType = grfThis.Properties("BoltType")
Dim NutType As Long
            NutType = grfThis.Properties("NutType")
Dim iDiam%
'            iDiam = grfThis.Properties("Diameter")

Dim dd#, D#, H#, T#, j#, del#, E#, F#
Dim HBolt, HNut, HWasher
            
'            dd = CDbl(frmBoltNut.ListDiam.List(iDiam))
            dd = grfThis.Properties("Diameter")
            
Dim Salp#, Calp#, L#, alp#
Dim X00#, Y00#, X01#, Y01#
            With grfThis.Vertices
                X00 = .Item(0).X
                Y00 = .Item(0).Y
                X01 = .Item(1).X
                Y01 = .Item(1).Y
                L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
                Salp = (Y01 - Y00) / L
                Calp = (X01 - X00) / L
            End With
            
       If Calp = 0# Then
          If Salp > 0 Then
              alp = Pi / 2#
              GoTo LL
          End If
          If Salp < 0 Then
              alp = 3# * Pi / 2#
              GoTo LL
          End If
       End If
            
       If Salp >= 0# And Calp > 0# Then
          alp = Atn(Abs(Salp / Calp))
       End If
       If Salp >= 0# And Calp < 0# Then
          alp = Pi - Atn(Abs(Salp / Calp))
       End If
       If Salp <= 0# And Calp < 0# Then
          alp = Pi + Atn(Abs(Salp / Calp))
       End If
       If Salp <= 0# And Calp > 0# Then
          alp = 2# * Pi - Atn(Abs(Salp / Calp))
       End If
LL:
            
            
Dim X0(30) As Double
Dim Y0(30) As Double
Dim X(30) As Double
Dim Y(30) As Double
       
Dim i As Integer
Dim grfChild As Object
       
       
 ' Slotted Countersunk Bolt  Slotted Countersunk Bolt  Slotted Countersunk Bolt
 ' Slotted Countersunk Bolt  Slotted Countersunk Bolt  Slotted Countersunk Bolt
    
    If BoltType = 0 Then
       
        D = 1.875 * dd
        H = 0.494 * dd
        T = 0.24 * dd
        j = 0.19 * dd
        del = 0.1 * dd
        HBolt = H
        
 ' Head of the Bolt
       X0(1) = H
       Y0(1) = dd / 2#
       
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = 0#
       Y0(3) = D / 2#
       
       X0(4) = X0(3)
       Y0(4) = -Y0(3)
       
       X0(5) = X0(3)
       Y0(5) = j / 2#
       
       X0(6) = X0(3)
       Y0(6) = -Y0(5)
       
       X0(7) = X0(3) + T
       Y0(7) = Y0(5)
       
       X0(8) = X0(7)
       Y0(8) = Y0(6)
       
       For i = 1 To 8
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
       
            'Add child Graphics
      '1
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(2), Y(2), 0#)
                  grfChild.Cosmetic = True
       '2
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(3), Y(3), 0#)
                  grfChild.Cosmetic = True
       '3
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
       '4
       Set grfChild = grfThis.Graphics.AddLineSingle(X(3), Y(3), 0#, X(5), Y(5), 0#)
                  grfChild.Cosmetic = True
       '5
       Set grfChild = grfThis.Graphics.AddLineSingle(X(4), Y(4), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
       '6
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
       '7
       Set grfChild = grfThis.Graphics.AddLineSingle(X(6), Y(6), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
       '8
       Set grfChild = grfThis.Graphics.AddLineSingle(X(7), Y(7), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
   End If
   
   
' Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt
' Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt  Hex Bolt
    
    If BoltType = 1 Then
        D = 1.75 * dd
        H = 0.65 * dd
        E = 0.8 * H
        F = D / 4#
        del = 0.1 * dd
        HBolt = H
       
'-----------------------------------------------------------
  ' Head of the Bolt
       X0(1) = H
       Y0(1) = D / 2#
       
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = X0(1)
       Y0(3) = F
       
       X0(4) = X0(1)
       Y0(4) = -Y0(3)
       
       X0(5) = H - E
       Y0(5) = D / 2#
       
       X0(6) = X0(5)
       Y0(6) = -Y0(5)
       
       X0(7) = 0#
       Y0(7) = D / 2# - (H - E)
       
       X0(8) = X0(7)
       Y0(8) = -Y0(7)
       
       X0(9) = X0(5)
       Y0(9) = Y0(3)
       
       X0(10) = X0(9)
       Y0(10) = -Y0(9)
       
       X0(11) = 0#
       Y0(11) = 3# / 2# * F
       
       X0(12) = X0(11)
       Y0(12) = 0#
       
       X0(13) = X0(11)
       Y0(13) = -Y0(11)
       
            
       
       
       For i = 1 To 13
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
       
            'Add child Graphics
'---------------------------------------------------------
       '6
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(2), Y(2), 0#)
                  grfChild.Cosmetic = True
       '7
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(5), Y(5), 0#)
                  grfChild.Cosmetic = True
       '8
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
       '9
       Set grfChild = grfThis.Graphics.AddLineSingle(X(3), Y(3), 0#, X(9), Y(9), 0#)
                  grfChild.Cosmetic = True
       '10
       Set grfChild = grfThis.Graphics.AddLineSingle(X(4), Y(4), 0#, X(10), Y(10), 0#)
                  grfChild.Cosmetic = True
       '11
       Set grfChild = grfThis.Graphics.AddLineSingle(X(7), Y(7), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
       '12
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
       '13
       Set grfChild = grfThis.Graphics.AddLineSingle(X(6), Y(6), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
       '14
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(5), Y(5), 0#, X(11), Y(11), 0#, X(9), Y(9), 0#)
                  grfChild.Cosmetic = True
       '15
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(9), Y(9), 0#, X(12), Y(12), 0#, X(10), Y(10), 0#)
                  grfChild.Cosmetic = True
       '16
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(10), Y(10), 0#, X(13), Y(13), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
                  
                                                                 
   End If
   
   
   
   
 ' Hex Nut  Hex Nut  Hex Nut  Hex Nut  Hex Nut  Hex Nut  Hex Nut
 ' Hex Nut  Hex Nut  Hex Nut  Hex Nut  Hex Nut  Hex Nut  Hex Nut
 
   If NutType = 0 Then
        D = 1.8 * dd
        H = 0.875 * dd
        E = 0.8 * H
        F = D / 4#
        del = (H - E) / 2#
        HNut = H
    
       
       X0(1) = L - HNut - dd / 4#
       Y0(1) = -D / 2# + del
   
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = X0(1) + del
       Y0(3) = Y0(2) + del
       
       X0(4) = X0(1) + H - del
       Y0(4) = Y0(3)
       
       X0(5) = X0(1) + H
       Y0(5) = Y0(4) - del
       
       X0(6) = X0(5)
       Y0(6) = -Y0(5)
       
       X0(7) = X0(6) - del
       Y0(7) = -Y0(4)
       
       X0(8) = X0(1) + del
       Y0(8) = -Y0(3)
       
       X0(9) = X0(1)
       Y0(9) = 3# / 2# * F
       
       X0(10) = X0(1)
       Y0(10) = 0#
       
       X0(11) = X0(1)
       Y0(11) = -Y0(9)
       
       X0(12) = X0(1) + del
       Y0(12) = F
       
       X0(13) = X0(12)
       Y0(13) = -Y0(12)
       
       X0(14) = X0(12) + E
       Y0(14) = Y0(12)
       
       X0(15) = X0(14)
       Y0(15) = Y0(13)
       
       X0(16) = X0(5)
       Y0(16) = Y0(9)
       
       X0(17) = X0(5)
       Y0(17) = Y0(10)
       
       X0(18) = X0(5)
       Y0(18) = Y0(11)
       
       
       For i = 1 To 18
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
      '1
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(2), Y(2), 0#)
                  grfChild.Cosmetic = True
      '2
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(3), Y(3), 0#)
                  grfChild.Cosmetic = True
      '3
       Set grfChild = grfThis.Graphics.AddLineSingle(X(3), Y(3), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
      '4
       Set grfChild = grfThis.Graphics.AddLineSingle(X(4), Y(4), 0#, X(5), Y(5), 0#)
                  grfChild.Cosmetic = True
      '5
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
      '6
       Set grfChild = grfThis.Graphics.AddLineSingle(X(6), Y(6), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
      '7
       Set grfChild = grfThis.Graphics.AddLineSingle(X(7), Y(7), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
      '8
       Set grfChild = grfThis.Graphics.AddLineSingle(X(8), Y(8), 0#, X(1), Y(1), 0#)
                  grfChild.Cosmetic = True
'---------------------------------------------------------------
       '9
       Set grfChild = grfThis.Graphics.AddLineSingle(X(13), Y(13), 0#, X(15), Y(15), 0#)
                  grfChild.Cosmetic = True
       '10
       Set grfChild = grfThis.Graphics.AddLineSingle(X(12), Y(12), 0#, X(14), Y(14), 0#)
                  grfChild.Cosmetic = True
'-----------------------------------------------------------------
       '11
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(3), Y(3), 0#, X(9), Y(9), 0#, X(12), Y(12), 0#)
                  grfChild.Cosmetic = True
       '12
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(12), Y(12), 0#, X(10), Y(10), 0#, X(13), Y(13), 0#)
                  grfChild.Cosmetic = True
       '13
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(13), Y(13), 0#, X(11), Y(11), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
       '14
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(4), Y(4), 0#, X(16), Y(16), 0#, X(14), Y(14), 0#)
                  grfChild.Cosmetic = True
       '15
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(14), Y(14), 0#, X(17), Y(17), 0#, X(15), Y(15), 0#)
                  grfChild.Cosmetic = True
       '16
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(15), Y(15), 0#, X(18), Y(18), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
                  
 ' End Of Bolt  End Of Bolt  End Of Bolt  End Of Bolt
       del = 0.1 * dd
        
       X0(1) = L - dd / 4#
       Y0(1) = dd / 2#
       
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = X0(1) + dd / 4# - del
       Y0(3) = dd / 2#
       
       X0(4) = X0(3)
       Y0(4) = -Y0(3)
       
       X0(5) = X0(3) + del
       Y0(5) = dd / 2# - del
       
       X0(6) = X0(5)
       Y0(6) = -Y0(5)
                  
       X0(7) = X0(1)
       Y0(7) = Y0(1) - del
                  
       X0(8) = X0(7)
       Y0(8) = -Y0(7)
                  
       X0(9) = X0(5) + 2#
       Y0(9) = 0#
                  
       For i = 1 To 9
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
       
       '0
       Set grfChild = grfThis.Graphics.AddLineSingle(X(3), Y(3), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
      '1
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(3), Y(3), 0#)
                  grfChild.Cosmetic = True
       '2
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
       '3
       Set grfChild = grfThis.Graphics.AddLineSingle(X(3), Y(3), 0#, X(5), Y(5), 0#)
                  grfChild.Cosmetic = True
       '4
       Set grfChild = grfThis.Graphics.AddLineSingle(X(4), Y(4), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
       '5
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
'--------------------
                  
        '6
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
        '7
       Set grfChild = grfThis.Graphics.AddLineSingle(X(6), Y(6), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
'----------------------------------------------------

' Middle of Bolt
                  
       X0(1) = HBolt
       Y0(1) = dd / 2#
   
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = L - HNut - dd / 4#
       Y0(3) = Y0(1)
       
       X0(4) = X0(3)
       Y0(4) = Y0(2)
' Threads
       X0(5) = (X0(1) + X0(3)) / 2#
       Y0(5) = Y0(1)
       
       X0(6) = X0(5)
       Y0(6) = -Y0(5)
       
       X0(7) = X0(5)
       Y0(7) = Y0(1) - del
       
       X0(8) = X0(5)
       Y0(8) = -Y0(7)
                  
       X0(9) = X0(3)
       Y0(9) = Y0(7)
       
       X0(10) = X0(9)
       Y0(10) = -Y0(9)
       
       For i = 1 To 10
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
      '1
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(3), Y(3), 0#)
                  grfChild.Cosmetic = True
      '2
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
      '3
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
      '4
       Set grfChild = grfThis.Graphics.AddLineSingle(X(7), Y(7), 0#, X(9), Y(9), 0#)
                  grfChild.Cosmetic = True
      '5
       Set grfChild = grfThis.Graphics.AddLineSingle(X(8), Y(8), 0#, X(10), Y(10), 0#)
                  grfChild.Cosmetic = True
                              
    End If
    
    
' Low Crown Nut  Low Crown Nut  Low Crown Nut  Low Crown Nut  Low Crown Nut
' Low Crown Nut  Low Crown Nut  Low Crown Nut  Low Crown Nut  Low Crown Nut
   
   If NutType = 1 Then
   
        D = 1.66 * dd
        H = 0.72 * dd
        E = 0.8 * H
        F = D / 4#
        del = (H - E) / 2#
        HNut = H + (D / 2# - del) * 1.2
    
       
       X0(1) = L - HNut
       Y0(1) = -D / 2# + del
   
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = X0(1) + del
       Y0(3) = Y0(2) + del
       
       X0(4) = X0(1) + H - del
       Y0(4) = Y0(3)
       
       X0(5) = X0(1) + H
       Y0(5) = Y0(4) - del
       
       X0(6) = X0(5)
       Y0(6) = -Y0(5)
       
       X0(7) = X0(6) - del
       Y0(7) = -Y0(4)
       
       X0(8) = X0(1) + del
       Y0(8) = -Y0(3)
       
       X0(9) = X0(1)
       Y0(9) = 3# / 2# * F
       
       X0(10) = X0(1)
       Y0(10) = 0#
       
       X0(11) = X0(1)
       Y0(11) = -Y0(9)
       
       X0(12) = X0(1) + del
       Y0(12) = F
       
       X0(13) = X0(12)
       Y0(13) = -Y0(12)
       
       X0(14) = X0(12) + E
       Y0(14) = Y0(12)
       
       X0(15) = X0(14)
       Y0(15) = Y0(13)
       
       X0(16) = X0(5)
       Y0(16) = Y0(9)
       
       X0(17) = X0(5)
       Y0(17) = Y0(10)
       
       X0(18) = X0(5)
       Y0(18) = Y0(11)
       
       X0(19) = X0(17) + (Y0(5) - Y0(17)) * 1.2
       Y0(19) = 0#
      
       
       
       For i = 1 To 19
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
      '1
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(2), Y(2), 0#)
                  grfChild.Cosmetic = True
      '2
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(3), Y(3), 0#)
                  grfChild.Cosmetic = True
      '3
       Set grfChild = grfThis.Graphics.AddLineSingle(X(3), Y(3), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
      '4
       Set grfChild = grfThis.Graphics.AddLineSingle(X(4), Y(4), 0#, X(5), Y(5), 0#)
                  grfChild.Cosmetic = True
      '5
       Set grfChild = grfThis.Graphics.AddArcRotatedElliptical(X(17), Y(17), 0#, X(5), Y(5), 0#, X(19), Y(19), 0#, Pi, 2# * Pi)
                  grfChild.Cosmetic = True
      '6
       Set grfChild = grfThis.Graphics.AddLineSingle(X(6), Y(6), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
      '7
       Set grfChild = grfThis.Graphics.AddLineSingle(X(7), Y(7), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
      '8
       Set grfChild = grfThis.Graphics.AddLineSingle(X(8), Y(8), 0#, X(1), Y(1), 0#)
                  grfChild.Cosmetic = True
'---------------------------------------------------------------
       '9
       Set grfChild = grfThis.Graphics.AddLineSingle(X(13), Y(13), 0#, X(15), Y(15), 0#)
                  grfChild.Cosmetic = True
       '10
       Set grfChild = grfThis.Graphics.AddLineSingle(X(12), Y(12), 0#, X(14), Y(14), 0#)
                  grfChild.Cosmetic = True
'-----------------------------------------------------------------
       '11
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(3), Y(3), 0#, X(9), Y(9), 0#, X(12), Y(12), 0#)
                  grfChild.Cosmetic = True
       '12
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(12), Y(12), 0#, X(10), Y(10), 0#, X(13), Y(13), 0#)
                  grfChild.Cosmetic = True
       '13
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(13), Y(13), 0#, X(11), Y(11), 0#, X(8), Y(8), 0#)
                  grfChild.Cosmetic = True
       '14
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(4), Y(4), 0#, X(16), Y(16), 0#, X(14), Y(14), 0#)
                  grfChild.Cosmetic = True
       '15
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(14), Y(14), 0#, X(17), Y(17), 0#, X(15), Y(15), 0#)
                  grfChild.Cosmetic = True
       '16
       Set grfChild = grfThis.Graphics.AddArcTriplePoint(X(15), Y(15), 0#, X(18), Y(18), 0#, X(7), Y(7), 0#)
                  grfChild.Cosmetic = True
                  
'----------------------------------------------------

' Middle of Bolt
                  
       X0(1) = HBolt
       Y0(1) = dd / 2#
   
       X0(2) = X0(1)
       Y0(2) = -Y0(1)
       
       X0(3) = L - HNut
       Y0(3) = Y0(1)
       
       X0(4) = X0(3)
       Y0(4) = Y0(2)
' Threads
       X0(5) = (X0(1) + X0(3)) / 2#
       Y0(5) = Y0(1)
       
       X0(6) = X0(5)
       Y0(6) = -Y0(5)
       
       X0(7) = X0(5)
       Y0(7) = Y0(1) - del
       
       X0(8) = X0(5)
       Y0(8) = -Y0(7)
                  
       X0(9) = X0(3)
       Y0(9) = Y0(7)
       
       X0(10) = X0(9)
       Y0(10) = -Y0(9)
       
       For i = 1 To 10
          X(i) = X00 + X0(i) * Calp - Y0(i) * Salp
          Y(i) = Y00 + X0(i) * Salp + Y0(i) * Calp
       Next i
      '1
       Set grfChild = grfThis.Graphics.AddLineSingle(X(1), Y(1), 0#, X(3), Y(3), 0#)
                  grfChild.Cosmetic = True
      '2
       Set grfChild = grfThis.Graphics.AddLineSingle(X(2), Y(2), 0#, X(4), Y(4), 0#)
                  grfChild.Cosmetic = True
      '3
       Set grfChild = grfThis.Graphics.AddLineSingle(X(5), Y(5), 0#, X(6), Y(6), 0#)
                  grfChild.Cosmetic = True
      '4
       Set grfChild = grfThis.Graphics.AddLineSingle(X(7), Y(7), 0#, X(9), Y(9), 0#)
                  grfChild.Cosmetic = True
      '5
       Set grfChild = grfThis.Graphics.AddLineSingle(X(8), Y(8), 0#, X(10), Y(10), 0#)
                  grfChild.Cosmetic = True
                              
                                           
   End If
    

            'Add visible child Graphics
        End If

        grfThis.RegenUnlock
        Exit Function

FailedLock:
        'Remove lock
        grfThis.RegenUnlock

Failed:
End Function

Public Function Draw(ByVal grfThis As Object, ByVal view As Object, Optional mat As Variant) As Boolean
    'Return True if we did the redraw (no further processing necessary, no children will be drawn).
    'Since this is just a test, we return False to let TurboCAD do the drawing operation.
    Draw = False
End Function

' Form string from string with symbols
Private Function StringToSize(Str As String) As Double
Dim CharInt(10) As String, j%
    CharInt(0) = "0"
    CharInt(1) = "1"
    CharInt(2) = "2"
    CharInt(3) = "3"
    CharInt(4) = "4"
    CharInt(5) = "5"
    CharInt(6) = "6"
    CharInt(7) = "7"
    CharInt(8) = "8"
    CharInt(9) = "9"
Dim StrLen%, i%
Dim Char$, ResStr$
    ResStr = ""
    StrLen = Len(Str)
    For i = 1 To StrLen
        Char = VBA.Mid(Str, i, 1)
        If Char = "0" Or Char = "1" Or Char = "2" Or Char = "3" Or Char = "4" Or Char = "5" Or Char = "6" Or Char = "7" Or Char = "8" Or Char = "9" Or Char = "." Or Char = "," Then
'            If Char = "," Then Char = "."
            ResStr = ResStr & Char
        End If
    Next i
    For i = 1 To StrLen
        Char = VBA.Mid(Str, i, 1)
        If Char = "-" Then
            ResStr = Char & ResStr
            Exit For
        End If
    Next i
    StringToSize = CDbl(ResStr)
End Function


